import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Test from '@/pages/test'
import Test2 from '@/pages/test2'
import game1 from '@/pages/game/game1'
import game2 from '@/pages/game/baike/baike.vue'
import game3 from '@/pages/game/game3'
import kaipao from '@/pages/game/kaipao/kaipao.vue' // 导入新组件
import fangpian from '@/pages/game/fangpian/fangpian.vue' // 导入防骗训练营组件

Vue.use(Router)

const router = new Router({
  base: '/game/',  // 和 publicPath 保持一致
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      path: '/test',
      name: 'Test',
      //component: (resolve) => require(['@/pages/test'], resolve),
      component: Test
    },
    {
      path: '/test2',
      name: 'Test2',
      component: Test2
    },
    {
      path: '/game1',
      name: 'game1',
      component: game1
    },
    {
      path: '/game2',
      name: 'game2',
      component: game2
    },
    {
      path: '/game3',
      name: 'game3',
      component: game3
    },
    {
      path: '/013min',
      name: '013min',
      title: '3分钟理解个复制知识点',
      component: (resolve) => require(['@/pages/game/13min/3min.vue'], resolve),
    },
    {
      path: '/kaipao', // 新路由路径
      name: 'kaipao', // 新路由名称
      meta: {
        title: '开怼'
      },
      component: kaipao // 新路由对应的组件
    },
    {
      path: '/cuoti',
      name: 'cuoti',
      title: '错题',
      component: () => import('@/pages/game/cuoti/cuoti.vue')
    },
    {
      path: '/sandwich',
      name: 'sandwich',
      title: '创意三明治',
      meta: {
        title: '创意三明治'
      },
      component: () => import('@/pages/game/sandwich/sandwich.vue')
    },
    {
      path: '/xuanxue',
      name: 'xuanxue',
      title: '玄学决策小助理',
      component: () => import('@/pages/game/xuanxue/xuanxue.vue')
    },
    {
      path: '/emoj',
      name: 'emoj',
      title: '表情密码',
      component: () => import('@/pages/game/emoj/emoj.vue')
    },
    {
      path: '/pic',
      name: 'pic',
      component: () => import('@/pages/game/pic/pic.vue')
    },
    {
      path: '/mengjing',
      name: 'mengjing',
      title: '梦境解析',
      component: () => import('@/pages/game/mengjing/mengjing.vue')
    }
    ,
    {
      path: '/badShare',
      name: 'badShare',
      title: 'AI反向智能推荐',
      component: () => import('@/pages/game/badShare/badShare.vue')
    },
    {
      path: '/12',
      name: '12',
      component: () => import('@/pages/game/test2/12/12.vue')
    },
    {
      path: '/universe',
      name: 'universe',
      title: '平行反向宇宙',
      component: () => import('@/pages/game/universe/universe.vue')
    },
    {
      path: '/zhiwu',
      name: 'zhiwu',
      meta: {
        title: '电子宠物--赛博植物'
      },
      component: () => import('@/pages/game/zhiwu/zhiwu.vue')
    },
    {
      path: '/fangpian',
      name: 'fangpian',
      meta: {
        title: '防骗训练营'
      },
      component: fangpian
    },
    {
      path: '/geng',
      name: 'geng',
      meta: {
        title: '梗友圈'
      },
      component: () => import('@/pages/game/geng/geng.vue')
    },
    {
      path: '/shige',
      name: 'shige',
      title: '诗歌',
      component: () => import('@/pages/game/shige/shige.vue')
    },
    {
      path: '/mingxing',
      name: 'mingxing',
      title: '明星',
      component: () => import('@/pages/game/mingxing/mingxing.vue')
    },
    {
      path: '/sentence',
      name: 'sentence',
      title: 'sentence',
      component: () => import('@/pages/sentence/sentence.vue')
    }
  ]
})

// 全局前置守卫，设置文档标题
router.beforeEach((to, from, next) => {
  console.log(to)
  // 优先使用 meta.title，如果没有则使用 title，最后使用路径作为标题
  document.title = (to.meta && to.meta.title) || to.title || to.path
  next()
})

export default router
